<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>图书列表</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/layui-admin/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="/layui-admin/css/font_eolqem241z66flxr.css" media="all" />
	<link rel="stylesheet" href="/layui-admin/css/news.css" media="all" />
	<script type="text/javascript" src="/layui-admin/layui/layui.js"></script>
	<script type="text/javascript" src="newsList.js"></script>
	<script src="/js/jquery-1.9.0.min.js"></script>
	<link rel="stylesheet" href="/layui-admin/css/simpleAlert.css">
	<script src="/layui-admin/js/simpleAlert.js"></script>
    <link rel="stylesheet" href="/layui-admin/css/jquery.pagination.css" />
    <script src="/layui-admin/js/jquery.pagination.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            font-family: "微软雅黑";
            background: #eee;
        }

        button {
            display: inline-block;
            padding: 6px 12px;
            font-weight: 400;
            line-height: 1.42857143;
            text-align: center;
            vertical-align: middle;
            cursor: pointer;
            border: 1px solid transparent;
            border-radius: 4px;
            border-color: #28a4c9;
            color: #fff;
            background-color: #5bc0de;
            margin: 20px 20px 0 0;
        }

        .box {
            width: 800px;
            margin: 100px auto 0;
            height: 34px;
        }

        .page {
            width: 600px;
        }

        .info {
            width: 200px;
            height: 34px;
            line-height: 34px;
        }

        .fl {
            float: left;
        }
    </style>
	<script type="text/javascript">
		$(document).ready(function(){
            get_books(1,10);
		});

		function get_books(pageNumber,pageSize){
            $("#book_include").html("");
            //弹出loading
            var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            setTimeout(function(){
                top.layer.close(index);
                layer.closeAll("iframe");
            },1500);
		    $.get("http://localhost:8080/get_book_by_page?pageNum="+pageNumber+"&pageSize="+pageSize,function(result){
		        var data = eval(result);
                var html = "";
		      	$.each(data.obj.list,function (indexs,values) {
                        html += "<tr>";
                        html +=     "<td hidden>" + values.bookId + "</td>"
                        html +=     "<td>" + Number(Number(indexs) + Number(1)) + "</td>"
                        html +=     "<td>" + "<img style='width: 40px;height: 40px;' src='/upload/bookimg/"+values.bookImg+"'>" + "</td>"
                        html +=     "<td>" + values.bookName + "</td>"
                        html +=     "<td>" + values.bookAnthou + "</td>"
                        html +=     "<td>" + values.score + "</td>"
                        html +=     "<td>" + values.downloadNumber + "</td>"
                        html +=     "<td>" + values.category.cName + "</td>"
                        html +=     "<td>" + values.user.nickname + "</td>"
                        html +=     "<td>" + "<div id='"+values.bookId+"' style='width: 50%;float:left; display:inline;cursor:pointer;' class='layui-icon'onclick='del_book(this.id)'>&#xe640;</div>"+"<div style='width: 50%; float:left; display:inline;cursor:pointer;' class='layui-icon' onclick='modify_book(this.id)' id='"+values.bookId+"'>&#xe642;</div>" + "</td>"
                        html += "</tr>";
                });
            $("#book_include").html(html);
                $("#book_comments").html(html);
                //执行一个laypage实例
                $("#pagination").pagination({
                    currentPage: 1,
                    totalPage:1 ,
                    isShow: false,
                    prevPageText: "< 上一页",
                    nextPageText: "下一页 >",
                    callback: function(current) {
                        get_comments(current,10);
                    }
                });
			})
		}
		function del_book(book_id) {
            var book = new FormData();
            book.append("bookID", book_id);
            var dblChoseAlert = simpleAlert({
                "content":"您确定要删除这本图书吗？",
                "buttons":{
                    "确定删除":function () {
                        $.ajax({
                            url: "http://localhost:8080/del_book",
                            data:book,
                            type: "post",
                            dataType: "json",
                            cache: false,//上传文件无需缓存
                            processData: false,//用于对data参数进行序列化处理 这里必须false
                            contentType: false, //必须
                            success: function (res) {
                                get_books(1,10);
                                layer.msg("图书删除成功")
                                dblChoseAlert.close();
                            },
                            error: function () {
                                get_books(1,10)
                                layer.msg("网络发生错误了")
                                dblChoseAlert.close();
                            },
                            beforeSend:function(){
                                //弹出loading
                                var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
                                setTimeout(function(){
                                    top.layer.close(index);
                                    layer.closeAll("iframe");
                                    dblChoseAlert.close();
                                },1500);
                            }
                        });
                    },
                    "容我想想":function () {
                        dblChoseAlert.close();
                    }
                }
            })
        }

        /**
		 * 修改图书
         */

        //修改图书
        function modify_book(book_id){
            var index = layui.layer.open({
                title : "修改图书",
                type : 2,
                content : "modify.html",
                success : function(layero, index){
                    $.get("/get_modify_message?bookId="+book_id,function(result){
                        var data = eval(result);
                        if(data.msg=="参数错误，该参数没有数据！"){
                            alert("这个参数没有数据");
                        }else{
                            var body = layer.getChildFrame('body', index);
                            var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            var inputList = body.find('input');
                            $(inputList[0]).val(book_id);
                            $(inputList[1]).val(data.obj.bookName);
                            $(inputList[2]).val(data.obj.bookAnthou);
                            body.find('textarea').val(data.obj.bookDetails);
                            var span = body.find('span');
                            $(span[0]).text(data.obj.bookImg);
                            $(span[1]).text(data.obj.download);
                        }
					}).error(function(result){
					    alert("网络出现了问题")
                    });
                }
            })
            //改变窗口大小时，重置弹窗的高度，防止超出可视区域（如F12调出debug的操作）
            $(window).resize(function(){
                layui.layer.full(index);
            })
            layui.layer.full(index);
        }
	</script>
</head>
<body class="childrenBody">
	<blockquote class="layui-elem-quote news_search">
		<div class="layui-inline">
		    <div class="layui-input-inline">
		    	<input type="text" id="search_book" value="" placeholder="请输入书名或作者姓名" class="layui-input search_input">
		    </div>
		    <a class="layui-btn search_btn" id="search">查询</a>
		</div>
		<div class="layui-inline">
			<a class="layui-btn layui-btn-normal newsAdd_btn">添加图书</a>
		</div>
		
	</blockquote>
	<div class="layui-form news_list">
	  	<table class="layui-table">
		    <colgroup>
				<col width="50">
				<col>
				<col width="9%">
				<col width="9%">
				<col width="9%">
				<col width="9%">
				<col width="9%">
				<col width="15%">
		    </colgroup>
		    <thead>
				<tr>
					<th style="width: 10%" hidden></th>
					<th style="width: 10%">编号</th>
					<th style="width: 10%">图书图片</th>
					<th style="width: 10%">名称</th>
					<th style="width: 10%">作者</th>
					<th style="width: 10%">评分</th>
					<th style="width: 10%">下载次数</th>
					<th style="width: 10%">分类名称</th>
					<th style="width: 10%">上传用户</th>
					<th style="width: 10%">图书操作</th>
				</tr>
			</thead>
		    <tbody class="news_content" id="book_include">

			</tbody>
		</table>
        <div class="box">
            <div id="pagination" class="page fl"></div>
            <!--<div class="info fl">-->
                <!--<p>当前页数：<span id="current">1</span></p>-->
            <!--</div>-->
        </div>
	</div>
	<div id="page"></div>

</body>
</html>